package com.zzmcc.wechat.service.impl;

import com.alibaba.fastjson.JSON;
import com.zzmcc.wechat.service.MenuService;
import com.zzmcc.wechat.util.HttpKit;
import org.smart4j.framework.tx.annotation.Service;

import java.util.Map;

/**
 * Created by joinwin on 14-7-11.
 */
@Service
public class MenuServiceImpl implements MenuService{
    /**
     * 创建菜单
     */
    @Override
    public boolean createMenu(String accessToken, String params) {
        String jsonStr = HttpKit.post("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken, params);
        Map<String, Object> map = JSON.parseObject(jsonStr, Map.class);
        return "0".equals(map.get("errcode").toString());
    }
    /**
     * 查询菜单
     */
    @Override
    public Map<String, Object> getMenuInfo(String accessToken) {
        String jsonStr = HttpKit.get("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken);
        Map<String, Object> map = JSON.parseObject(jsonStr, Map.class);
        return map;
    }
    /**
     * 删除自定义菜单
     */
    @Override
    public boolean deleteMenu(String accessToken) {
        String jsonStr = HttpKit.get("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accessToken);
        Map<String, Object> map = JSON.parseObject(jsonStr, Map.class);
        return "0".equals(map.get("errcode").toString());
    }
}
